package com.sport.annotation;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

public class WorkTypeSerializer extends JsonSerializer<String> {

    @Override
    public void serialize(String workType, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        String convertedWorkType = convertWorkType(workType);
        gen.writeString(convertedWorkType);
    }

    private String convertWorkType(String workType) {
        if ("城网".equals(workType)) {
            return "城镇";
        } else if ("乡网".equals(workType)) {
            return "乡村";
        } else {
            return workType; // 如果不是 "城网" 或 "乡网"，则保持原值
        }
    }
}
